package com.niit.agricstore.controller;

import com.niit.agricstore.entity.Aftersale;
import com.niit.agricstore.entity.Logistics;
import com.niit.agricstore.entity.Order;
import com.niit.agricstore.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;

    /**订单信息**/
    //查询已发货的订单信息
    @GetMapping("/shipped")
    public List<Order> getShippedOrders() {
        return orderService.getShippedOrders();
    }
    //根据订单编号查询物流信息
    @GetMapping("/{orderId}/logistics")
    public Logistics getLogisticsInfo(@PathVariable int orderId) {
        return orderService.getLogisticsInfo(orderId);
    }
    //更新订单的收货状态
    @PutMapping("/{orderId}")
    public void updateOrderShippingStatus(@PathVariable int orderId, @RequestParam("status") String shippingStatus) {
        orderService.updateOrderShippingStatus(orderId, shippingStatus);
    }

    /**订单管理**/
    //确认订单、更新发货状态
    @PostMapping("/confirm/{orderId}")
    public void confirmOrder(@PathVariable int orderId) {
        orderService.confirmOrder(orderId);
    }

    //获取退款申请列表
    @GetMapping("/aftersale/list")
    public List<Aftersale> getAftersaleList() {
        return orderService.getAftersaleList();
    }

    //同意退款申请
    @PostMapping("/aftersale/approve/{aftersale_id}")
    public void approveRefundApplication(@PathVariable int aftersale_id) {
        orderService.approveRefundApplication(aftersale_id);
    }
//
//    //拒绝退款申请
//    @PostMapping("/aftersale/reject/{aftersale_id}")
//    public void rejectRefundApplication(@PathVariable int aftersale_id) {
//        orderService.rejectRefundApplication(aftersale_id);
//    }

    //更新订单状态
    @PostMapping("/updateStatus/{orderId}/{status}")
    public void updateOrderStatus(@PathVariable int orderId, @PathVariable int status) {
        orderService.updateOrderStatus(orderId, status);
    }

    //添加售后记录
    @PostMapping("/aftersale/add")
    public void addAfterSale(@RequestBody Aftersale aftersale) {
        orderService.addAfterSale(aftersale);
    }

    //确认售后申请
    @PostMapping("/aftersale/confirm/{aftersale_id}")
    public void confirmAfterSale(@PathVariable int aftersale_id, @RequestParam String address) {
        orderService.confirmAfterSale(aftersale_id, address);
    }

    //拒绝售后申请
    @PostMapping("/aftersale/reject/{aftersale_id}")
    public void rejectAfterSale(@PathVariable int aftersale_id, @RequestParam String reason) {
        orderService.rejectAfterSale(aftersale_id, reason);
    }

    //获取售后记录详情
    @GetMapping("/aftersale/{aftersale_id}")
    public Aftersale getAfterSaleById(@PathVariable int aftersale_id) {
        return orderService.getAfterSaleById(aftersale_id);
    }


}
